package org.jeecg.modules.simulator.factory.train.plan;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: simulator-b20240918
 * @description:
 * @author: renzhg
 * @create: 2024-10-04 11:07
 **/
public class ParkJsonSaverRead  implements ParkTrainLoader{


    @Getter
    List<Train2Parker> tplist;

    public void createTrainMap() {
//        tplist.forEach(e -> {
//            List<MetroTrain> metroTrainList = new ArrayList<>();
//            for (int i = 0; i < e.getSavers(); i++) {
//                MetroTrain metroTrain = new MetroTrain();
//                metroTrain.setGroupId(UUID.randomUUID().toString());
//                metroTrain.setTrainPhysics(trainPhysicsMap.get("1号车型"));
//                metroTrainList.add(metroTrain);
//            }
//            noAssignMetroTrainMap.put(e.getParkerId(), metroTrainList);
//        });
    }

    @Override
    public void dataLoad() {
        tplist = trainPsread("D:/aaaa/parksavers.json");

    }


    public List<Train2Parker> trainPsread(String path) {
        List<Train2Parker> train2ParkerList = new ArrayList<>();
        try {
            String jsonString = new String(Files.readAllBytes(Paths.get(path)));
            JSONArray jsonArray = JSON.parseArray(jsonString);
            for (int i = 0; i < jsonArray.size(); i++) {
                Train2Parker train2Parker = new Train2Parker();
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                int savers = jsonObject.getInteger("savers");
                train2Parker.setSavers(savers);
                String parkerId = jsonObject.getString("parkerId");
                train2Parker.setParkerId(parkerId);
                train2ParkerList.add(train2Parker);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return train2ParkerList;

    }
}
